;
(function (window, angular) {
    'use strict';
    angular.module("Controller.Personal.Password", [])
        .controller("PasswordCtrl", ["$scope", "$state", "ybWidget", "ybHttp", "MESG_TYPE", "UserContextService", function ($scope, $state, ybWidget, ybHttp, MESG_TYPE, UserContextService) {
            $scope.submitted = false;
            $scope.detailInfo = {
                oldPwd: "",
                newPwd: "",
                confirmPwd: ""
            };

            $scope.saveData = function (isValid) {
                if (!isValid) {
                    $scope.submitted = true;
                    return;
                }

                if ($scope.detailInfo.newPwd !== $scope.detailInfo.confirmPwd) {
                    return;
                }
                var service = "auth";
                var reqUrl = "/auth/password";
                var param = {};
                param.newPassword = $scope.detailInfo.newPwd;
                param.oldPassword = $scope.detailInfo.oldPwd;
                ybHttp.Post(service, reqUrl, param).then(function (resp) {
                    if (resp.code !== 0) {
                        ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                        return;
                    }
                    $scope.submitted = false;
                    ybWidget.ShowMessage("操作成功<br>请重新登录", MESG_TYPE.Success, {isHtml: true}).then(function () {
                        UserContextService.Logout();
                    });
                });
            };
        }])
    ;
})(window, window.angular);